package com.lightsaber.trade.cloth.service.planning.impl;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lightsaber.trade.core.dao.BaseDao;
import com.lightsaber.trade.core.entity.AuditedObject;
import com.lightsaber.trade.core.entity.BaseEntity;
import com.lightsaber.trade.core.service.HppBaseServiceImpl;
import com.lightsaber.trade.cloth.dao.planning.AdminDutyDao;
import com.lightsaber.trade.cloth.entity.planning.AdminDuty;
import com.lightsaber.trade.cloth.service.planning.AdminDutyService;

@Service
@Component
@Transactional
public class AdminDutyServiceImpl extends HppBaseServiceImpl<AdminDuty, String> implements
        AdminDutyService {

    private static final Logger log = LoggerFactory.getLogger(AdminDuty.class);

    @Autowired
    private AdminDutyDao adminDutyDao;

    @Override
    protected BaseDao<AdminDuty, String> getDao() {
        return adminDutyDao;
    }

    @Override
    public void save(final AdminDuty adminDuty) {
        if (StringUtils.isBlank(adminDuty.getId())) {
            adminDutyDao.save(adminDuty);
        } else {
            AdminDuty old = get(adminDuty.getId());
            BeanUtils.copyProperties(adminDuty, old, new String[] { BaseEntity.ID,
                    BaseEntity.VERSION, "level3Planning", AuditedObject.CREATED_BY,
                    AuditedObject.CREATED_DATE });
            adminDutyDao.update(old);
        }

    }

    @Override
    public AdminDuty findUniqueAdminDuty(final String level3PlanningId, final String discipline,
            final String campus, final String dep, final int year) {
        return adminDutyDao.findUniqueAdminDuty(level3PlanningId, discipline, campus, dep, year);
    }

    @Override
    public AdminDuty findById(final String dutyId) {
        return adminDutyDao.get(dutyId);
    }
}
